var entityCollection = require('../../../Base/server/controllers/EntityCollection');

//通过编码查找扩展枚举
exports.getExtendEnum = function(code, completeFun){
    var entity = entityCollection.getEntity('ExtendEnum');
    entity.findOne({Code: code}, null, function(err, record){
        if(err){
            var newErr = new Error();
            err.leval = 9;
            err.title = '系统查询错误';
            err.message = '通过编码查询扩展枚举失败，请检查查询条件';
            completeFun(newErr);
        }
        else {
            if(record != null) {
                var extendEnum = {};
                for(var i=0; i<record.Options.length; i++){
                    extendEnum["Enum" + i.toString()] = {
                        Value: record.Options[i].Value, 
                        Text: record.Options[i].Name
                    }
                }
                completeFun(null, extendEnum);
            }
            else{
                completeFun(null, null);
            }
        }
    });
};